package com.cn.zpark;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @PackageName: com.cn.zpark
 * @ClassName: ServletConfigDemo02
 * @Description:
 * @author: RZS
 * @date: 2022/4/8  10:02
 */
public class ServletConfigDemo02 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 直接获取servletConfig对象
        ServletConfig servletConfig = this.getServletConfig();
        // 获取servlet名字
        String servletName = servletConfig.getServletName();
        System.out.println(servletName);
        // 获取当前servlet初始化参数
        String username = servletConfig.getInitParameter("username");
        String pwd = servletConfig.getInitParameter("pwd");
        System.out.println(username + " : " + pwd);
    }
}
